package com.comprehensive.personalnotes.service.impl;

import com.comprehensive.common.dto.FolderFlieInfo;
import com.comprehensive.personalnotes.feign.FileServiceFeignClient;
import com.comprehensive.personalnotes.service.NotesService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NotesServiceImpl implements NotesService {
    @Autowired
    private FileServiceFeignClient fileServiceFeignClient;
    @Value("${notes.path}")
    private String notesPath;


    @Override
    public ResponseEntity<List<FolderFlieInfo>> listFiles(String directoryPath) {
        if (StringUtils.isBlank(directoryPath)) {
            directoryPath=notesPath;
        }
        return fileServiceFeignClient.listFiles(directoryPath);
    }

    @Override
    public ResponseEntity<String> getMarkdownContent(String filePath) {
        return fileServiceFeignClient.getMarkdownContent(filePath);
    }

    @Override
    public ResponseEntity<Void> saveMarkdownContent(String filePath, String content) {
        return fileServiceFeignClient.saveMarkdownContent(filePath, content);
    }
}
